package com.tpyule.tpclass.web.Controller;

import com.tpyule.tpclass.entity.bean.FailResultBean;
import com.tpyule.tpclass.entity.bean.ResultBean;
import com.tpyule.tpclass.entity.bean.SuccessResultBean;
import com.tpyule.tpclass.entity.pojo.Record;
import com.tpyule.tpclass.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zzz
 * @version 1.0
 * @date 2020/4/7 23:56
 */
@RestController
@RequestMapping("record")
public class RecordController extends BaseController {
    @Autowired
    RecordService recordService;


    @RequestMapping("/getRecordByUserId")
    @ResponseBody
    public void getRecordByUserId(HttpServletRequest request, HttpServletResponse response) throws IOException {
        ResultBean resultBean=null;
        String userId = request.getParameter("userId");
        if (userId!=null) {
            List<Record> records = recordService.listRecordByUserId(userId);
            resultBean = new SuccessResultBean<List<Record>>(records,"获取成功！");
        }else {
            resultBean = new FailResultBean("失败");
        }
        this.setAjaxResponseResult(response,resultBean);
    }
}
